package com.gonsin.gmessage.logic.proxy.receiver;

import com.gonsin.gmessage.logic.model.GMessageModel;
import com.gonsin.gmessage.logic.model.ReceiveMessageModel;
import com.gonsin.gmessage.logic.websocket.MessageBo;
import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;
import java.util.Set;

@Slf4j
public class MessageContainer {

    /**
     * 接收消息之后回调接口容器
     */
    private Set<GMessageCallback> callbacks = new HashSet<>();

    /**
     * 接收到消息
     * @param message
     */
    public void notifyMessageReceive(GMessageModel message){
        for(GMessageCallback callback : callbacks){
            try {
                callback.onReceive(message);
            } catch (Exception ex) {
                log.error(ex.toString(), ex);
            }
        }
    }

    public void addCallback(GMessageCallback callback) {
        this.callbacks.add(callback);
    }
}
